package com.shu.project.controller;

import com.shu.framework.enums.CodeMsg;
import com.shu.framework.exception.user.UserException;
import com.shu.framework.result.Result;
import com.shu.framework.utils.MD5Util;
import com.shu.framework.utils.StringUtils;
import com.shu.framework.utils.ValidatorUtil;
import com.shu.project.model.User;
import com.shu.project.service.IUserService;
import com.shu.project.vo.LoginVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@Controller
@RequestMapping("/login")
public class LoginController {
    private static final Logger log = LoggerFactory.getLogger(LoginController.class);

    @Autowired
    IUserService userService;
    @RequestMapping("/to_login")
    public String toLogin(){
        return "login";
    }
    @RequestMapping("/do_login")
    @ResponseBody
    public Result<CodeMsg> doLogin   (@Valid LoginVo loginVo, HttpServletResponse response, HttpServletRequest request){
        log.info(loginVo.toString());
        userService.login(response,loginVo);
        return Result.success(CodeMsg.SUCCESS);
    }
}
